import { Controller, Get, Post, Body, Param } from '@nestjs/common';
import { CoffeesService } from './coffees.service';
import { CreateCoffeeDto } from './dto/create-coffee.dto';
import { Coffee } from './entities/coffee.entity';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';

@ApiTags('coffees')
@Controller('coffees')
export class CoffeesController {
  constructor(private readonly coffeesService: CoffeesService) {}

  @Post()
  @ApiOperation({ summary: '添加一种新咖啡' })
  @ApiResponse({ status: 201, description: '咖啡已成功添加', type: Coffee })
  create(@Body() createCoffeeDto: CreateCoffeeDto): Coffee {
    return this.coffeesService.create(createCoffeeDto);
  }

  @Get()
  @ApiOperation({ summary: '获取所有咖啡' })
  @ApiResponse({
    status: 200,
    description: '返回所有咖啡列表',
    type: Coffee,
    isArray: true,
  })
  findAll(): Coffee[] {
    return this.coffeesService.findAll();
  }

  @Get(':id')
  @ApiOperation({ summary: '根据ID获取咖啡' })
  @ApiResponse({ status: 200, description: '返回指定ID的咖啡', type: Coffee })
  @ApiResponse({ status: 404, description: '咖啡未找到' })
  findOne(@Param('id') id: string): Coffee | undefined {
    return this.coffeesService.findOne(+id);
  }

  @Get('recommend/:catName')
  @ApiOperation({ summary: '为指定猫咪推荐咖啡' })
  @ApiResponse({
    status: 200,
    description: '返回推荐的咖啡',
    type: Coffee,
  })
  recommendForCat(@Param('catName') catName: string): Coffee {
    return this.coffeesService.recommendForCat(catName);
  }
}
